package com.sdwz.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.Strings;
import com.sdwz.user.entity.StuInfo;
import com.sdwz.user.entity.vo.StuInfoVo;
import com.sdwz.user.mapper.StuInfoMapper;
import com.sdwz.user.service.StuInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 学生信息表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-03-28
 */
@Service
public class StuInfoServiceImpl extends ServiceImpl<StuInfoMapper, StuInfo> implements StuInfoService {

    /**
     * 根据条件分页查询，获得id集合
     * @param current
     * @param limit
     * @param stuInfoVo
     * @return
     */
    @Override
    public List<String> getStuInfoList(long current, long limit, StuInfoVo stuInfoVo) {
        QueryWrapper<StuInfo> wrapper = new QueryWrapper<>();
        String stuNo = stuInfoVo.getStuNo();
        String stuName = stuInfoVo.getStuName();
        String school = stuInfoVo.getSchool();
        if (Strings.isNullOrEmpty(stuNo)){
            wrapper.eq("stu_no",stuNo);
        }
        if (Strings.isNullOrEmpty(stuName)){
            wrapper.like("stu_name",stuName);
        }
        if (Strings.isNullOrEmpty(school)){
            wrapper.like("school",school);
        }
        Page<StuInfo> page = new Page<>(current,limit);
        Page<StuInfo> stuInfoPage = baseMapper.selectPage(page, wrapper);
        List<StuInfo> records = stuInfoPage.getRecords();
        List<String> stuIds = new ArrayList<>();
        for (StuInfo stuInfo:records){
            stuIds.add(stuInfo.getId());
        }
        return stuIds;
    }
}
